import java.util.Map;
import java.util.TreeMap;

public class Solution2171 {
    public long minimumRemoval(int[] beans) {
        TreeMap<Integer,Integer> map=new TreeMap<>();
        long sum=0L;
        for (int bean : beans) {
            sum+=bean;
            map.put(bean,map.getOrDefault(bean,0)+1);
        }
        map.put(0,0);
        long num=0L;
        long ans=Long.MAX_VALUE;
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            ans=Math.min(ans,sum-entry.getKey()*(beans.length-num));
            num=num+entry.getValue();
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution2171().minimumRemoval(new int[]{4,1,6,5}));
    }
}
